1   /*
2    * Copyright (C) 2011 The Guava Authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  
15  package com.google.common.collect;
16  
17  import javax.annotation.Nullable;
18  
19  /**
20   * A descending wrapper around an {@code ImmutableSortedMultiset}
21   *
22   * @author Louis Wasserman
23   */
24  @SuppressWarnings("serial") // uses writeReplace, not default serialization
25  final class DescendingImmutableSortedMultiset<E> extends ImmutableSortedMultiset<E> {
26    private final transient ImmutableSortedMultiset<E> forward;
27  
28    DescendingImmutableSortedMultiset(ImmutableSortedMultiset<E> forward) {
29      this.forward = forward;
30    }
31  
32    @Override
33    public int count(@Nullable Object element) {
34      return forward.count(element);
35    }
36  
37    @Override
38    public Entry<E> firstEntry() {
39      return forward.lastEntry();
40    }
41  
42    @Override
43    public Entry<E> lastEntry() {
44      return forward.firstEntry();
45    }
46  
47    @Override
48    public int size() {
49      return forward.size();
50    }
51  
52    @Override
53    public ImmutableSortedSet<E> elementSet() {
54      return forward.elementSet().descendingSet();
55    }
56  
57    @Override
58    Entry<E> getEntry(int index) {
59      return forward.entrySet().asList().reverse().get(index);
60    }
61  
62    @Override
63    public ImmutableSortedMultiset<E> descendingMultiset() {
64      return forward;
65    }
66  
67    @Override
68    public ImmutableSortedMultiset<E> headMultiset(E upperBound, BoundType boundType) {
69      return forward.tailMultiset(upperBound, boundType).descendingMultiset();
70    }
71  
72    @Override
73    public ImmutableSortedMultiset<E> tailMultiset(E lowerBound, BoundType boundType) {
74      return forward.headMultiset(lowerBound, boundType).descendingMultiset();
75    }
76  
77    @Override
78    boolean isPartialView() {
79      return forward.isPartialView();
80    }
81  }